<template>
  <div class="line-detail">
    <span class="table-blue" @click="back">
      <i class="iconfont icon-left"></i>返回
    </span>
    <Form class="businessForm" :model="busSetting" label-position="right" :label-width="140">
      <div class="title">基础配置</div>
      <div class="box">
        <Row>
          <Col span="18">
          <Row>
            <Col span="12">
            <FormItem label="业务名称">
              <Row>
                <i-col span="24">
                  <i-input v-model="busSetting.modeName" placeholder="业务标注方式名称"></i-input>
                </i-col>
              </Row>
            </FormItem>
            </Col>
            <Col span="12">
            <FormItem label="简短描述">
              <Row>
                <i-col span="24">
                  <i-input v-model="busSetting.describe" placeholder="业务线的简短描述"></i-input>
                </i-col>
              </Row>
            </FormItem>
            </Col>
          </Row>
          </Col>
        </Row>
      </div>

      <div class="title">业务配置</div>

      <div class="box">
        <Row>
          <Col span="18">
          <Row>
            <Col span="12" v-for="(value,key) in busSetting.tasks" :key="key + 'aaaaa'">
            <FormItem v-if="taskflowNode.indexOf(key)=='-1'" :label="cname[key]">
              <Row>
                <i-col span="24">
                  <i-input v-model="busSetting.tasks[key]" :placeholder="key"></i-input>
                </i-col>
              </Row>
            </FormItem>
            <FormItem v-else :label="cname[key]" >
              <Row>
                <i-col span="24">
                  <i-select v-model="busSetting.tasks[key]" placeholder="请选择">
                    <i-option
                      v-for="(item,index) in pipelineList"
                      :key="item.id+index+key"
                      :value="item.id"
                    >{{item.name}}</i-option>
                  </i-select>
                </i-col>
              </Row>
            </FormItem>
            </Col>
          </Row>
          </Col>
        </Row>
      </div>
      <!--回收转移放弃-->
      <div class="title">回收配置</div>

      <div class="box">
        <Row>
          <Col span="21">
          <Row>
            <Col span="9">
            <FormItem label="删除文件类型">
              <Row>
                <i-col span="24">
                  <RadioGroup v-model="flow[0].recovery.removeStatus">
                    <Radio label="0">
                      <span>未完成</span>
                    </Radio>
                    <Radio label="1">
                      <span>已完成</span>
                    </Radio>
                    <Radio label="-1">
                      <span>全部</span>
                    </Radio>
                  </RadioGroup>
                </i-col>
              </Row>
            </FormItem>
            </Col>
            <Col span="6">
            <FormItem label="提交已标注">
              <Row>
                <i-col span="24">
                  <Checkbox v-model="flow[0].recovery.isSubmitProcessed">
                    <span v-if="flow[0].recovery.isSubmitProcessed == true">是</span>
                    <span v-else>否</span>
                  </Checkbox>
                </i-col>
              </Row>
            </FormItem>
            </Col>
          </Row>
          </Col>
        </Row>
      </div>
      <div class="title">转移配置</div>

      <div class="box">
        <Row>
          <Col span="21">
          <Row>
            <Col span="9">
            <FormItem label="删除文件类型">
              <Row>
                <i-col span="24">
                  <RadioGroup v-model="flow[0].transfer.removeStatus">
                    <Radio label="0">
                      <span>未完成</span>
                    </Radio>
                    <Radio label="1">
                      <span>已完成</span>
                    </Radio>
                    <Radio label="-1">
                      <span>全部</span>
                    </Radio>
                  </RadioGroup>
                </i-col>
              </Row>
            </FormItem>
            </Col>
            <Col span="6">
            <FormItem label="提交已标注">
              <Row>
                <i-col span="24">
                  <Checkbox v-model="flow[0].transfer.isSubmitProcessed">
                    <span v-if="flow[0].transfer.isSubmitProcessed == true">是</span>
                    <span v-else>否</span>
                  </Checkbox>
                </i-col>
              </Row>
            </FormItem>
            </Col>
            <Col span="6">
            <FormItem label="删除结果">
              <Row>
                <i-col span="24">
                  <Checkbox v-model="flow[0].transfer.isRemoveResult">
                    <span v-if="flow[0].transfer.isRemoveResult == true">是</span>
                    <span v-else>否</span>
                  </Checkbox>
                </i-col>
              </Row>
            </FormItem>
            </Col>
          </Row>
          </Col>
        </Row>
      </div>
      <div class="title">放弃配置</div>

      <div class="box">
        <Row>
          <Col span="21">
          <Row>
            <Col span="9">
            <FormItem label="删除文件类型">
              <Row>
                <i-col span="24">
                  <RadioGroup v-model="flow[0].giveup.removeStatus">
                    <Radio label="0">
                      <span>未完成</span>
                    </Radio>
                    <Radio label="1">
                      <span>已完成</span>
                    </Radio>
                    <Radio label="-1">
                      <span>全部</span>
                    </Radio>
                  </RadioGroup>
                </i-col>
              </Row>
            </FormItem>
            </Col>
            <Col span="5">
            <FormItem label="提交已标注">
              <Row>
                <i-col span="24">
                  <Checkbox v-model="flow[0].giveup.isSubmitProcessed">
                    <span v-if="flow[0].giveup.isSubmitProcessed == true">是</span>
                    <span v-else>否</span>
                  </Checkbox>
                </i-col>
              </Row>
            </FormItem>
            </Col>
            <Col span="5">
            <FormItem label="删除结果">
              <Row>
                <i-col span="24">
                  <Checkbox v-model="flow[0].giveup.isRemoveResult">
                    <span v-if="flow[0].giveup.isRemoveResult == true">是</span>
                    <span v-else>否</span>
                  </Checkbox>
                </i-col>
              </Row>
            </FormItem>
            </Col>
            <Col span="5">
            <FormItem label="更新默认结果">
              <Row>
                <i-col span="24">
                  <Checkbox v-model="flow[0].giveup.isUpdateResult">
                    <span v-if="flow[0].giveup.isUpdateResult == true">是</span>
                    <span v-else>否</span>
                  </Checkbox>
                </i-col>
              </Row>
            </FormItem>
            </Col>
          </Row>
          </Col>
        </Row>
      </div>

      <!--/回收转移放弃-->

      <Row>
        <i-col span="18" style="text-align:left; margin:50px 0;">
          <Row>
            <Col span="8">&nbsp;</Col>
            <Col span="8">
            <div style="padding-left:140px;">
              <Button type="primary" style="width:120px;" :loading="loading" size="large" @click="saveBusiness">提 交</Button>
            </div>
            </Col>
            <Col span="8">&nbsp;</Col>
          </Row>
        </i-col>
      </Row>
    </Form>

  </div>
</template>

<script>
import { getListDetail, saveListDetail, getPipeline } from 'http/api/linemanage';

export default {
  name: 'LineDetail',
  data () {
    return {
      modelId: '',
      busSetting: {// 新增和编辑需要传递的参数
        modeName: '',
        describe: '',
        tasks: {
          createBatchTaskFlowId: '',
          taskExportTaskFlowId: '',
          recoveryStrategy: '',
          transferStrategy: ''
        }
      },
      flow: [
        {
          step: 0,
          recovery: {
            isSubmitProcessed: true, // 提交已标注
            removeStatus: '0' // 删除文件类型// "0"/"1"/"-1"   默认值：0
          },
          giveup: {
            isSubmitProcessed: false, // 是否提交已标注:  默认值false
            isRemoveResult: false, // 是否删除result表中的结果
            isUpdateResult: false, // 是否更新file中默认结果
            removeStatus: '-1'// 删除文件类型// "0"/"1"/"-1"   默认值：-1
          },
          transfer: {
            isSubmitProcessed: true, // 是否提交已处理的:  默认值true
            isRemoveResult: false, // 是否删除result表中的结果
            removeStatus: '0'// 删除文件类型// "0"/"1"/"-1"   默认值：0
          }
        }
      ],
      taskflowNode: ['createBatchTaskFlowId', 'taskExportTaskFlowId'],
      cname: {// 节点名称
        createBatchTaskFlowId: '创建批次任务流',
        taskExportTaskFlowId: '导出任务流',
        recoveryStrategy: '回收策略',
        transferStrategy: '转移策略'
      },
      loading: false, // 提交按钮 loading 显示状态
      searchValue: '', // 工作流快捷检索
      pipelineList: null// 可选工作流列表
    };
  },
  methods: {
    back () {
      this.$router.push({ path: '/home/linemanage/linelist' });
    },
    getBusDetail () {
      getListDetail(this.modelId)
        .then(res => {
          if (res) {
            if (res.data.tasks == null) {
              this.$Message.error('获取tasks失败');
              return;
            }
            if (res.data.views == null) {
              this.$Message.error('获取views失败,前端是否还没传页面呢？');
              return;
            }
            this.modelId = res.data.modelId;
            if (res.data.isNew) {
              this.busSetting.isNew = res.data.isNew;
            }
            this.busSetting.modeName = res.data.modeName;
            this.busSetting.describe = res.data.describe;
            this.$set(this.busSetting, 'tasks', res.data.tasks);
          }
        })
        .catch(err => {
          this.$Message.error('获取当前业务信息失败！详细信息：' + err);
        });
    },
    saveBusiness () {
      this.loading = true;
      this.$set(this.busSetting.tasks, 'flow', this.flow);
      // this.busSetting.tasks.flow = this.flow;
      saveListDetail({ id: this.modelId, data: this.busSetting })
        .then(res => {
          if (res) {
            this.$Message.success('很棒，添加成功了！');
          }
          this.loading = false;
        })
        .catch(err => {
          this.$Message.error('添加失败，快看看接口咋地了？详细信息：' + err);
          this.loading = false;
        });
    },
    // 查询工作流列表
    getPipeline () {
      let param = {
        name: this.searchValue,
        pageIndex: 1,
        pageSize: 100
      };
      getPipeline(param).then(res => {
        if (res) {
          this.pipelineList = res.data.pipelineStates;
        }
      });
    }
  },
  mounted () {
    if (this.$route.query.modelId) {
      this.modelId = this.$route.query.modelId;
      this.getBusDetail();
    }
    this.getPipeline();
  }
};
</script>

<style rel="stylesheet/less" lang="less" scoped>
.businessForm {
  border-top: 1px solid #d6d6d6;
  padding-top: 20px;
  .title {
    padding-left: 140px;
    font-size: 16px;
    line-height: 40px;
    font-weight: bold;
    padding-top: 20px;
  }
  .box{
    border-bottom:1px dashed #d6d6d6
    }
}
.line-detail {
  .table-blue {
    display: inline-block;
    margin: 20px;
    font-size: 12px;
    .icon-left {
      font-size: 12px;
    }
  }
}
</style>

<style lang="less">
</style>
